﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using Confluent.Kafka;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;

using Ccteg.Common;
using Ccteg.DB;

namespace Cctegaq.Api.Controllers.Api.V1.Rbac
{
    /// <summary>
    /// 任务信息
    /// </summary>
    [ApiController]
    [Route("api/v1/rbac/[controller]/[action]")]
    public class TaskController : Controller
    {
        private readonly MySqlDbContext _dbContext;
        private readonly IMapper _mapper;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="mapper"></param>
        public TaskController(MySqlDbContext dbContext, IMapper mapper)
        {
            _dbContext = dbContext;
            _mapper = mapper;
        }




        /// <summary>
        /// 获取安全任务列表
        /// </summary>
        /// <param name="word"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Get_tsk_jobtaskList(string word)
        {
            var response = new ResponseModel<List<tsk_jobtask>>();
            using (_dbContext)
            {

                var list = _dbContext.tsk_jobtask.ToList();
                response.SetData(list);
            }
            return Ok(response);
        }

        /// <summary>
        /// 获取安全任务列表
        /// </summary>
        /// <param name="JobTaskID">任务id</param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateTaskState(int JobTaskID)
        {
            var response = new ResponseModel<string>();
            var sql = "UPDATE tsk_jobtask SET State=@State WHERE JobTaskID =" + JobTaskID;
            var parameters = new List<MySqlParameter>();
            parameters.Add(new MySqlParameter("@State", "已下发"));
            _dbContext.Database.ExecuteSqlRaw(sql, parameters);
            return Ok(1);
             
        }
    }
}
